package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.liveData
import androidx.lifecycle.switchMap
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.base.BpBaseViewModel
import com.bp.hearthealth.pulse.lnapps.bp_extension.UIHelperBp

/**
 * @author isnoam
 * @package_name DiscoverViewModel.kt
 * @description：
 */
class BpHomeViewModel(private val repository: BpHomeRepository) : BpBaseViewModel() {

    private val userId = MutableLiveData<String>()

    var firstText = MutableLiveData(UIHelperBp.getString(R.string._healthy_diet_tips_1_str))
    var secondText = MutableLiveData(UIHelperBp.getString(R.string._healthy_diet_tips_6_str))
    var thirdText = MutableLiveData(UIHelperBp.getString(R.string._healthy_diet_tips_2_str))
    var firstUrl = MutableLiveData(R.mipmap.hd_1)
    var secondUrl = MutableLiveData(R.mipmap.hd_2)
    var thirdUrl = MutableLiveData(R.mipmap.hd_3)

    fun loadHeartRateBean(id: String) {
        userId.value = id
    }

    val heartRateBean = userId.switchMap {
        liveData {
            val result = try {
                val updateUnlocked = repository.loadHeartRateBean(it)
                Result.success(updateUnlocked)
            } catch (e: Exception) {
                Result.failure(e)
            }
            emit(result)
        }
    }
}